<?php
session_start();
?>
<style>
.rojo td
    {
        background: #ff9994 !important;
        -moz-opacity: 0.50;
     	filter: alpha(opacity=85);
     	-khtml-opacity: .85;
     	opacity: .85;
    }
.amarillo td
    {
        background: #FFFFDD !important;
        -opacity: 0.50;
     	filter: alpha(opacity=85);
     	-khtml-opacity: .85;
     	opacity: .85;
    }
.verde td
    {
        background: #DFFFDF !important;
        -opacity: 0.50;
     	filter: alpha(opacity=85);
     	-khtml-opacity: .85;
     	opacity: .85;
    }
.sinColor tr
    {
        background: transparent !important;
    }
</style>
<?php
$esAdmin = $_SESSION['admin'];

include("conexion.php");
$var = new conexion();
$var->conectarse();

$sql= stripslashes ($_POST['variable']);

if($sql != "")
	{
         //................................................................................
         //.. Copio la consulta para tenerla y poder ordenar por algun campo el resultado .
         //................................................................................
         $consulta = explode("ORDER BY", $sql);
         $consulta = $consulta[0];
         echo '<input type="hidden" name="consul" id="consul" value="'.$consulta.'"/>';
         //................................................................................
         
		$resu = mysql_query($sql) or (die(mysql_error()));
		
		if(mysql_num_rows($resu) >  0)
			{
			     $sql = $sql."@@@";
			    echo '<input type="hidden" name="consulImpr" id="consulImpr" value="'.$sql.'"/>'; 
				echo "<img src=\"assest/plugins/buttons/icons/printer.png\" title=\"Imprimir Filtro\"
                 onClick=\"ImprimirNuevo();\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;";
                 //onClick="">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;';
				echo '<img src="assest/plugins/buttons/icons/icono_excel.gif" title="Exportar a Exel" onclick="ExportarExcel();">';
			echo "<table>
				<thead><tr>
				<td style=\"text-align: center;\"><br>
                                                <table style=\"height: 5px;\">
                                                    <tr>
                                                        <td style=\"text-align: right;\"><b><label>Nro Pedido</label></b></td>
                                                        <td>
                                                            <img src=\"assest/plugins/buttons/icons/arriba.png\" onClick=\"Ordenamiento('1','ASC');\" title=\"Ascendente\"><br>
                                                            <img src=\"assest/plugins/buttons/icons/abajo.png\" onClick=\"Ordenamiento('1','DESC');\" title=\"Descendente\">
                                                        </td>
                                                    </tr> 
                                                  </table>        
                 </td>
				<td style=\"text-align: center;\"><br>
                                                <table>
                                                    <tr>
                                                        <td style=\"text-align: right;\"><b><label>Cliente</label></b></td>
                                                        <td>
                                                            <img src=\"assest/plugins/buttons/icons/arriba.png\" onClick=\"Ordenamiento('2','ASC');\" title=\"Ascendente\"><br>
                                                            <img src=\"assest/plugins/buttons/icons/abajo.png\" onClick=\"Ordenamiento('2','DESC');\" title=\"Descendente\">
                                                        </td>
                                                    </tr> 
                                                  </table> 
                </td>				
				<td style=\"text-align: center;\"><br>
                                                <table>
                                                    <tr>
                                                        <td style=\"text-align: right;\"><b><label>Art&iacute;culo</label></b></td>
                                                        <td>
                                                            <img src=\"assest/plugins/buttons/icons/arriba.png\" onClick=\"Ordenamiento('3','ASC');\" title=\"Ascendente\"><br>
                                                            <img src=\"assest/plugins/buttons/icons/abajo.png\" onClick=\"Ordenamiento('3','DESC');\" title=\"Descendente\">
                                                        </td>
                                                    </tr> 
                                                  </table> 
                </td>
				<td style=\"text-align: center;\"><br>
                                                <table>
                                                    <tr>
                                                        <td style=\"text-align: right;\"><b><label>Fecha</label></b></td>
                                                        <td>
                                                            <img src=\"assest/plugins/buttons/icons/arriba.png\" onClick=\"Ordenamiento('4','ASC');\" title=\"Ascendente\"><br>
                                                            <img src=\"assest/plugins/buttons/icons/abajo.png\" onClick=\"Ordenamiento('4','DESC');\" title=\"Descendente\">
                                                        </td>
                                                    </tr> 
                                                  </table> 
                </td>
                <td style=\"text-align: center;\"><br>
                                                <table>
                                                    <tr>
                                                        <td style=\"text-align: center;\"><b><label>Estado</label></b></td>
                                                    </tr> 
                                                  </table> 
                </td>
                <td style=\"text-align: center;\"><br>
                                                <table>
                                                    <tr>
                                                        <td style=\"text-align: center;\"><b><label>Imprimir</label></b></td>
                                                    </tr> 
                                                  </table> 
                </td>
				</tr></thead>";
				while($row = mysql_fetch_array($resu))
					{	
						echo '
							<tr class="'.DeterminaColor($row['estado']).'">
                                <td>'.$row['nro'].'</td>
								<td>'.utf8_encode($row['clie']).'</td>
								<td>'.utf8_encode($row['arti']).'</td>
								<td style="text-align: center;">'.invertirFecha($row['fecha']).'</td>
                                <td style="text-align: center;">'.DeterminaEstado($row['estado']).'</td>
                                <td style="text-align: center;"><img src="assest/plugins/buttons/icons/printer.png" title="Imprimir Pedido" onClick="ImprimirReporte(\''.$row['id'].'\')"></td>
							 </tr>
						';
					}

			echo '</table>';
			}else
				{
				echo '<b><i>No se encontraron resultados.</i></b>';
				}
	}else
		{
		echo "<b><i>Filtro no v&aacute;lido.</i></b>";	
		}
//--------------- FUNCIONES -------------------
function invertirFecha($date)
	{
		$dato = explode('-',$date);
		$dato = $dato[2] ."-". $dato[1] ."-". $dato[0];
		return $dato;
	}
    
function DeterminaEstado($estado)
    {
        switch($estado)
            {
                case "I":
                    return "Ingresado";
                    break;
                case "A":
                    return "Aceptado";
                    break;
                case "V":
                    return "Aprobado";
                    break;
                case "T":
                    return "Terminado";
                    break;
                case "EP":
                    return "Ter.Parcial";
                    break;
                default:
                    return "Sin Estado";
                    break;
            }
    }
    
function DeterminaColor($estado)
    {
        switch($estado)
            {
                case "T":
                    return "verde";
                    break;
                case "EP":
                    return "amarillo";
                    break;
                default:
                    return "rojo";
                    break;
            }
    }
//---------------------------------------------
?>